package com.yihaodian.search.code.manage.handler;

import java.util.ArrayList;
import java.util.List;

import org.tmatesoft.svn.core.SVNCancelException;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNNodeKind;
import org.tmatesoft.svn.core.wc.ISVNEventHandler;
import org.tmatesoft.svn.core.wc.SVNEvent;
import org.tmatesoft.svn.core.wc.SVNEventAction;
import org.tmatesoft.svn.core.wc.SVNInfo;

import com.yihaodian.search.code.model.UpdateCodeEntry;
import com.yihaodian.search.code.util.SvnUtil;

public class UpdateEventHandler implements ISVNEventHandler {

	private List<UpdateCodeEntry> updateList = new ArrayList<UpdateCodeEntry>();

	public void clearUpdateList() {
		updateList.clear();
	}

	public List<UpdateCodeEntry> getUpdateList() {
		return updateList;
	}

	@Override
	public void checkCancelled() throws SVNCancelException {
	}

	@Override
	// 处理变更的svn文档
	public void handleEvent(SVNEvent event, double progress) throws SVNException {
		SVNEventAction action = event.getAction();
		SVNNodeKind nodeKind = event.getNodeKind();

		if (SVNNodeKind.DIR.equals(nodeKind)) {
			return;
		} else if (action == SVNEventAction.UPDATE_ADD || action == SVNEventAction.UPDATE_UPDATE
				|| action == SVNEventAction.UPDATE_DELETE) {
			try {
				if (event.getFile().getPath().contains("search-code") || event.getFile().getPath().contains("search-mars")) {
					updateList.add(new UpdateCodeEntry(event.getFile(), action));
				}
				
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

}
